using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.EventSystems;

public class StatSlotUI : MonoBehaviour,IPointerEnterHandler,IPointerExitHandler
{
    [SerializeField] private string statName;

    [SerializeField] private StatType statType;
    [SerializeField] private TextMeshProUGUI statValueText;
    [SerializeField] private TextMeshProUGUI statNameText;

    [TextArea]
    [SerializeField] private string statDescription;


    private void Start()
    {
        UpdateStatValueUI();
    }

    private void OnValidate()
    {
        gameObject.name = "Stat - " + statName;

        if (statNameText!=null)
        {
            statNameText.text = statName;
        }
    }

    public void UpdateStatValueUI()
    {
        PlayerStats playerStats = PlayerManager.instance.player.GetComponent<PlayerStats>();

        if (playerStats!=null)
        {
            statValueText.text = playerStats.GetStat(statType).GetValue().ToString();

            if (statType==StatType.health)
            {
                statValueText.text = playerStats.GetMaxHealthValue().ToString();
            }

            switch (statType)
            {
                case StatType.strength:
                    break;
                case StatType.agility:

                    break;
                case StatType.intelegence:
                    break;
                case StatType.vitality:
                    break;
                case StatType.damage:
                    statValueText.text = (playerStats.damage.GetValue()+playerStats.strength.GetValue()).ToString();
                    break;
                case StatType.critChance:
                    statValueText.text = (playerStats.critChance.GetValue()+playerStats.agility.GetValue()).ToString();
                    break;
                case StatType.critPower:
                    statValueText.text = (playerStats.critPower.GetValue() + playerStats.strength.GetValue()).ToString();
                    break;
                case StatType.health:
                    statValueText.text = playerStats.GetMaxHealthValue().ToString();
                    break;
                case StatType.armor:
                    break;
                case StatType.evasion:
                    statValueText.text = (playerStats.evasion.GetValue() + playerStats.agility.GetValue()).ToString();
                    break;
                case StatType.magicRes:
                    statValueText.text = (playerStats.magicResistance.GetValue() + playerStats.intelegence.GetValue()*.3f).ToString();
                    break;
                case StatType.fireDamage:
                    break;
                case StatType.iceDamage:
                    break;
                case StatType.lightingDamage:
                    break;
                default:
                    break;
            }

        }
    }

    public void OnPointerEnter(PointerEventData eventData)
    {
        UIManager.instance.statToolTipUI.ShowStatToolTip(statDescription);
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        UIManager.instance.statToolTipUI.HideStatToolTip();
    }
}
